package com.xxx.auth.service;

import com.xxx.auth.common.util.LoginUserUtil;
import com.xxx.auth.entity.Project;
import com.xxx.auth.repository.ProjectRepository;
import com.xxx.auth.web.vo.CreateProjectForm;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class ProjectService {

    private final ProjectRepository projectRepository;
    private final HttpServletRequest request;

    /**
     * 创建项目
     *
     * @param form 表单数据
     * @return 项目id
     */
    public String createProject(CreateProjectForm form) {
        Project project = new Project();
        BeanUtils.copyProperties(form, project);
        project.setCreatorId(LoginUserUtil.getLoginUserId(request));

        projectRepository.save(project);
        return project.getId();
    }

}
